<template>
  <div class="tag-input-wrapper" @click="$emit('click')">
    <div class="tag-input-content">
      <template v-if="selectedFriends.length > 0">
        <el-tag v-for="friend in selectedFriends" :key="friend.wx_id" closable @close.stop="$emit('remove', friend)" class="input-tag">
          {{ friend.nick_name }}
        </el-tag>
      </template>
      <span v-else class="placeholder">{{ placeholder }}</span>
    </div>
    <el-icon class="search-icon" @click.stop="$emit('click')"><Search /></el-icon>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { Search } from '@element-plus/icons-vue';

interface Tag {
  id: string;
  label_name: string;
}

interface Friend {
  wx_id: string;
  nick_name: string;
  first_nick_name: string;
  avatar: string;
  gender: string;
  labels: Tag[];
}

export default defineComponent({
  name: 'FriendTagInput',
  components: {
    Search
  },
  props: {
    selectedFriends: {
      type: Array as () => Friend[],
      default: () => []
    },
    placeholder: {
      type: String,
      default: '点击选择好友'
    }
  },
  emits: ['click', 'remove']
});
</script>

<style lang="scss" scoped>
.tag-input-wrapper {
  width: 100%;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  cursor: pointer;
  background-color: #fff;
  transition: all 0.3s;

  &:hover {
    border-color: #c0c4cc;
  }

  .tag-input-content {
    flex: 1;
    min-height: 32px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  .placeholder {
    color: #c0c4cc;
    font-size: 14px;
  }

  .search-icon {
    color: #c0c4cc;
    font-size: 16px;
    margin-left: 8px;
    cursor: pointer;

    &:hover {
      color: #409eff;
    }
  }

  .input-tag {
    margin: 3px;
    height: 24px;
    line-height: 22px;
    padding: 0 8px;
    font-size: 12px;
  }
}
</style> 